package com.taobao.top
{
	import com.adobe.serialization.json.JSON;
	public class TOPDelivery
	{
		public function TOPDelivery()
		{
		}
		/**
		 * 发货处理 
		 * 
		 */		
		public function sendDelivery(tid:String,orderType:String,company_code:String="",out_sid:String="",seller_name:String="",seller_area_id:String="",seller_address:String="",seller_zip:String="",seller_phone:String="",seller_mobile:String="",memo:String=""):void
		{
			var topURLLdr:TOPURLLoader = new TOPURLLoader();
			var reqParamArr:Array = new Array();
			reqParamArr=[new TopRequestParam("method","taobao.delivery.send "),
				new TopRequestParam("tid",tid),new TopRequestParam("orderType",orderType)];
				
			if(company_code!= "")
			{
				reqParamArr.push(new TopRequestParam("company_code",company_code));
			}
			
			if(out_sid!= "")
			{
				reqParamArr.push(new TopRequestParam("out_sid",out_sid));
			}
			
			if(seller_name!= "")
			{
				reqParamArr.push(new TopRequestParam("seller_name",seller_name));
			}
			
			if(seller_area_id!= "")
			{
				reqParamArr.push(new TopRequestParam("seller_area_id",seller_area_id));
			}
			
			if(seller_address!= "")
			{
				reqParamArr.push(new TopRequestParam("seller_address",seller_address));
			}
			
			if(seller_zip!= "")
			{
				reqParamArr.push(new TopRequestParam("seller_zip",seller_zip));
			}
			
			if(seller_phone!= "")
			{
				reqParamArr.push(new TopRequestParam("seller_phone",seller_phone));
			}
			
			if(seller_mobile!= "")
			{
				reqParamArr.push(new TopRequestParam("seller_mobile",seller_mobile));
			}
			
			if(memo!= "")
			{
				reqParamArr.push(new TopRequestParam("memo",memo));
			}
			
			topURLLdr.addEventListener(Event.COMPLETE,deliverySendHandler);
			topURLLdr.loadData(reqParamArr);
		}
		
		private function deliverySendHandler(event:Event):void
		{
			switch(event.type)
			{
				case Event.COMPLETE:
					var isSuccess:Boolean = deliverySendJsonParser(event.target.data);
				break;
				default:
					 dispatchEvent(event.clone());
				break;
			}
		}
		
		private function deliverySendJsonParser(jsonStr:String):Boolean
		{
			if(TOPError.isError(jsonStr))
			{
				var topError:TOPError = TOPError.parseError(jsonStr);
				//dispatchEvent(new ErrorEvent(ErrorEvent.ERROR,false,false,
			}else
			{
				var deliverySendObj:Object = JSON.decode(jsonStr);
				return deliverySendObj.rsp.isSuccess;
			}
			return false;
		}
	}
}